function gradient = gauss2DProjGradient(params, mu1, sigma1, mu2, sigma2)

% compute negative gradient of closed form L2 measure between two Gaussian

trans = params(1:2);
proj = reshape(params(3:6), 2, 2);

mu = [proj*mu1']' + trans - mu2;
sigma = proj*sigma1*proj' + sigma2;

mu_grad = gaussMeanGradient(mu, sigma, zeros(size(mu)));
sigma_grad = gaussCovarianceGradient(mu, sigma, zeros(size(mu)));

mu_proj_grad = scaleGradient(proj, mu1);
sigma_proj_grad = quadGradient(proj, sigma1);

proj_grad = zeros(size(proj));
for i = 1:size(proj, 1)
    for j = 1:size(proj, 2)
        m_p_g = mu_proj_grad(:, i, j);
        s_p_g = sigma_proj_grad(:, :, i, j);
        proj_grad(i, j) = sigma_grad(:)'*s_p_g(:) + mu_grad(:)'*m_p_g(:);
    end
end

trans_grad = mu_grad;
proj_grad = proj_grad(:);

gradient = [trans_grad; proj_grad];
